package com.alit.url.manager.generator;

import javax.sql.DataSource;

import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.generator.Generator;
import com.jfinal.plugin.druid.DruidPlugin;

import lombok.extern.slf4j.Slf4j;

/**
 * @author litong
 * @date 2019年6月10日_下午3:47:05
 * @version 1.0
 * @desc
 */
@Slf4j
public class Model {
  public static void main(String[] args) {
    PropKit.use("undertow.txt");
    String jdbcDriver = PropKit.get("jdbc.driver");
    String jdbcUrl = PropKit.get("jdbc.url");
    String jdbcUser = PropKit.get("jdbc.user");
    String jdbcPswd = PropKit.get("jdbc.pswd");
    log.info(jdbcDriver + "," + jdbcUrl + "," + jdbcUser + "," + jdbcPswd);
    DruidPlugin dp = new DruidPlugin(jdbcUrl, jdbcUser, jdbcPswd, jdbcDriver);
    dp.start(); // 初始化数据源
    DataSource dataSource = dp.getDataSource(); // 获取数据源
    System.out.println(dataSource);
    // base model 所使用的包名
    String baseModelPkg = "model.base";
    // base model 文件保存路径
    String baseModelDir = PathKit.getWebRootPath() + "/../src/model/base";
    // model 所使用的包名
    String modelPkg = "model";
    // model 文件保存路径
    String modelDir = baseModelDir + "/..";
    Generator gernerator = new Generator(dataSource, baseModelPkg, baseModelDir, modelPkg, modelDir);
    // 在 getter、setter 方法上生成字段备注内容
    gernerator.setGenerateRemarks(true);
    gernerator.generate();
  }
}
